Skip to content

Conversation

@stephenwilliams22
Copy link
Collaborator

@stephenwilliams22 stephenwilliams22 commented Oct 6, 2025

This pr adds support for cell segmentation in Visium HD which was added in Space Ranger 4.0.

Features include

  • Updating and refactoring the visium_hd function
  • Default loading of Visium HD cell segmentations
  • New parameters
    • load_segmentations_only which disables bin loading
    • load_nucleus_segmentations which loads nucleus segmentations and calculates a nucleus only expression matrix

spatial data structure will look something like

SpatialData object
├── Images
│     ├── 'hd_hires_image': DataArray[cyx] (3, 5394, 6000)
│     └── 'hd_lowres_image': DataArray[cyx] (3, 540, 600)
├── Shapes
│     ├── 'hd_cell_segmentations': GeoDataFrame shape: (612, 2) (2D shapes)
│     └── 'hd_nucleus_segmentations': GeoDataFrame shape: (950, 2) (2D shapes)
└── Tables
      ├── 'cell_segmentations': AnnData (612, 32285)
      └── 'nucleus_segmentations': AnnData (950, 32285)
with coordinate systems:
    ▸ 'hd_downscaled_hires', with elements:
        hd_hires_image (Images), hd_cell_segmentations (Shapes), hd_nucleus_segmentations (Shapes)
    ▸ 'hd_downscaled_lowres', with elements:
        hd_lowres_image (Images), hd_cell_segmentations (Shapes), hd_nucleus_segmentations (Shapes)

To do based on submission guidelines

@codecov-commenter
Copy link

codecov-commenter commented Oct 6, 2025

Codecov Report

❌ Patch coverage is 94.11765% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 55.13%. Comparing base (7cccdd1) to head (62c3f9f).
⚠️ Report is 27 commits behind head on main.

Files with missing lines Patch % Lines
src/spatialdata_io/readers/visium_hd.py 92.85% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #328      +/-   ##
==========================================
+ Coverage   49.06%   55.13%   +6.06%     
==========================================
  Files          26       26              
  Lines        2686     2802     +116     
==========================================
+ Hits         1318     1545     +227     
+ Misses       1368     1257     -111     
Files with missing lines Coverage Δ
src/spatialdata_io/__main__.py 86.03% <100.00%> (ø)
src/spatialdata_io/_constants/_constants.py 100.00% <100.00%> (ø)
src/spatialdata_io/readers/visium_hd.py 76.36% <92.85%> (+61.23%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@stephenwilliams22
Copy link
Collaborator Author

@LucaMarconato please let me know if my vignette should go someplace else but I thought it would be good to have one.

Comment on lines 47 to 71

# TODO: Replace with the actual Visium HD test dataset folder name
# This dataset name is used to locate the test data in the './data/' directory.
# See https://github.com/scverse/spatialdata-io/blob/main/.github/workflows/prepare_test_data.yaml
# for instructions on how to download and place the data on disk.
DATASET_FOLDER = "Visium_HD_Mouse_Brain_Chunk"
DATASET_ID = "visium_hd_tiny"


@skip_if_below_python_version()
def test_visium_hd_data_extent() -> None:
"""Check the spatial extent of the loaded Visium HD data."""
f = Path("./data") / DATASET_FOLDER
if not f.is_dir():
pytest.skip(f"Test data not found at '{f}'. Skipping extent test.")

sdata = visium_hd(f, dataset_id=DATASET_ID)
extent = get_extent(sdata, exact=False)
extent = {ax: (math.floor(extent[ax][0]), math.ceil(extent[ax][1])) for ax in extent}

# TODO: Replace with the actual expected extent of your test data
expected_extent = "{'x': (1000, 7000), 'y': (2000, 8000)}"
assert str(extent) == expected_extent


Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to update these once tiny test is added

@LucaMarconato
Copy link
Member

Thanks @stephenwilliams22! We can review the vignette here, but before merging please move it to the spatialdata-notebooks repo, in this folder.

If you would like we could add the vignette in gallery in the docs.

@stephenwilliams22
Copy link
Collaborator Author

stephenwilliams22 commented Oct 13, 2025

Thanks @stephenwilliams22! We can review the vignette here, but before merging please move it to the spatialdata-notebooks repo, in this folder.

If you would like we could add the vignette in gallery in the docs.

Perfect. moved here scverse/spatialdata-notebooks#152

@stephenwilliams22 stephenwilliams22 marked this pull request as ready for review October 29, 2025 18:58
@stephenwilliams22
Copy link
Collaborator Author

@LucaMarconato tests updated. Let me know what you think!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants